package com.linghu.study.springbootshirojwtdemo.utils;

import com.linghu.study.springbootshirojwtdemo.reponse.Response;

/**
 * @author: linghu
 * @date:
 * @version: 1.0.0
 * @description: 接口返回工具类
 */
public class ResponseUtil {

    public static Response success(Object result) {
        Response response = new Response();
        response.setStatus("true");
        response.setMsg("操作成功!");
        response.setResult(result);
        response.setData("null");
        return response;
    }

    public static Response success(Object result, String msg,String data,String status) {
        Response response = new Response();
        response.setData(data);
        response.setMsg(msg);
        response.setStatus(status);
        return response;
    }

    public static Response success(String data,String msg) {
        Response response = new Response();
        response.setData(data);
        response.setMsg(msg);
        return response;
    }

    public static Response error(Object result) {
        Response response = new Response();

        response.setMsg("登录失败!");
        response.setResult(result);
        return response;
    }

    public static Response error(Object result, String msg) {
        Response response = new Response();
        response.setMsg(msg);
        response.setResult(result);
        return response;
    }

    public static Response error(Object result, String msg,String data,String status) {
        Response response = new Response();
        response.setData(data);
        response.setMsg(msg);
        response.setStatus(status);
        response.setResult(result);
        return response;
    }

    public static Response checkStatus(int flag) {
        return flag > 0 ? ResponseUtil.success(flag) : ResponseUtil.error(flag);
    }

    public static Response checkStatus(Object object) {
        return object == null ? ResponseUtil.error(null) : ResponseUtil.success(object);
    }

}
